import {Component} from '@angular/core';
import {ApesField} from '@shared/ui-zorro/src/types/apes-field';
import {ApiService} from '@core/services/http/api.service';
import {Events} from '@core/services/events/Events';
import {ExpressionService} from '@core/services/expression/ExpressionService';
import {SubjectService} from '@core/services/events/subject.service';
import { exists, getO } from '../../../../utils/utils';
import { toNumbers } from '@angular/compiler-cli/src/diagnostics/typescript_version';

@Component({
  selector: 'formly-field-switch',
  template: `
    <div class="apes-field-switch">
      <ng-container *ngFor="let check of list; index as i;">
        <apes-switch [(ngModel)]="check.checked"
                     [formControl]="formControl"
                     [formlyAttributes]="field"
                     [apesDisabled]="to.disabled"
                     apesCheckedChildren="{{check.select}}"
                     apesUnCheckedChildren="{{check.unSelect}}"></apes-switch>
      </ng-container>
    </div>
  `
})
export class FormlyFieldSwitch extends ApesField {

  ctx:any = {};
  list = [];

  constructor(
    protected apiService: ApiService,
    protected events: Events,
    protected expressionService: ExpressionService,
    protected subject: SubjectService
  ) {
    super(apiService, events, expressionService, subject);
  }

  ngOnInit(): void {
    this.ctx = this.formState;
    this.list = getO(this.to.list);
  }

}
